package com.iddaa.core.util;

import java.net.UnknownHostException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoException;

public class MongoFactory {
	
	private String url;
	private int port;
	private String db;
	private Mongo mongo;
	private DB database;

	private static final Logger logger = LoggerFactory.getLogger(MongoFactory.class);

	protected void init() {
		try {
			mongo = new Mongo(url, port);
			database = mongo.getDB(db);
		} catch (UnknownHostException e) {
			logger.error(e.getMessage());
		} catch (MongoException e) {
			logger.error(e.getMessage());
		}
	}

	public DBCollection loadCollection(String name) {
		return database.getCollection(name);
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public String getDb() {
		return db;
	}

	public void setDb(String db) {
		this.db = db;
	}


}
